﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class EnemyManager : MonoBehaviour
{
    public GameObject enemyPreviewPrefab;
    public GameObject enemyPreviewBar;
    private Dictionary<GameObject, GameObject> EnemyPreviewDict = new Dictionary<GameObject, GameObject>();


    public void AddEnemy(GameObject enemy)
    {
        if (!enemy || EnemyPreviewDict.ContainsKey(enemy))
        {
            return;
        }

        GameObject prefab = Instantiate(enemyPreviewPrefab);
        prefab.GetComponent<EnemyPreviewerBehaviour>().belongEnemyObject = enemy;
        prefab.transform.SetParent(enemyPreviewBar.transform);

        EnemyPreviewDict.Add(enemy, prefab);
    }

    public void RemoveEnemy(GameObject enemy)
    {
        if (!enemy || !EnemyPreviewDict.ContainsKey(enemy))
        {
            return;
        }
        GameObject prefab = EnemyPreviewDict[enemy];
        for (int i = 0; i < enemyPreviewBar.transform.childCount; i++)
        {
            if (enemyPreviewBar.transform.GetChild(i) == prefab)
            {
                Destroy(enemyPreviewBar.transform.GetChild(i));
            }
        }

        EnemyPreviewDict.Remove(enemy);
    }

    private void Initial()
    {
        
    }

    private void Start()
    {
        Initial();
    }
}
